﻿using Microsoft.Extensions.Logging;
using SqlSugar;
using System.Numerics;
using WMS.Common;
using WMS.Model;
using WMS.Repository.IRepository;

namespace WMS.Repository
{
    public class LogRepository : BaseRepository<UserModel>, ILogRepository
    {
        public LogRepository(ISqlSugarClient db, ILogger<LogRepository> logger) : base(db, logger)
        {
        }

        /// <summary>
        /// 查询账号是否存在
        /// </summary>
        public async Task<UserModel> GetAccountAsync(string account)
        {
            try
            {
                return await _db.Queryable<UserModel>().Where(x => x.Account == account).FirstAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"查询账号失败 - 账号: {account}");
                throw;
            }
        }

        /// <summary>
        /// 查询邮箱是否存在
        /// </summary>
        public async Task<UserModel> GetEmailAsync(string email)
        {
            try
            {
                return await _db.Queryable<UserModel>().Where(x => x.Email == email).FirstAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"查询邮箱失败 - 邮箱: {email}");
                throw;
            }
        }
    }
}